home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 January / PC Plus Super CD No55a (PCP-147A-1-99) (Disc 1) (1998).iso / linux / developers / visualtcl / windows / vtcl / lib / command.tcl < prev    next >
Encoding:
Text File  |  1997-10-23  |  4.8 KB  |  155 lines

  1. ##############################################################################
  2. # $Id: command.tcl,v 1.13 1997/10/24 01:47:40 stewart Exp $
  3. #
  4. # command.tcl - procedures to update widget commands
  5. #
  6. # Copyright (C) 1996-1997 Stewart Allen
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. ##############################################################################
  23. #
  24.  
  25. proc vTcl:edit_wincmd {which} {
  26.     global vTcl
  27.     set target $vTcl(w,widget)
  28.     set base ".vTcl.com_${which}_[vTcl:rename $target]"
  29.     if [catch {set cmd [info body vTclWindow($which)$target]}] {
  30.         set cmd ""
  31.     }
  32.     set cmd [string trim $cmd]
  33.     set r [vTcl:get_command "Window ${which}Command for $target" $cmd $base]
  34.     if {$r == -1} {
  35.         return
  36.     } else {
  37.         set procname vTclWindow($which)$target
  38.         vTcl:list add "{$procname}" vTcl(procs)
  39.         proc $procname {args} $r
  40.     }
  41. }
  42.  
  43. proc vTcl:set_command {target {option -command}} {
  44.     global vTcl
  45.     if {$target == ""} {return}
  46.     set base ".vTcl.com_[vTcl:rename ${target}${option}]"
  47.     if {[catch {set cmd [$target cget $option]}] == 1} {
  48.         return
  49.     }
  50.     set r [vTcl:get_command "$option for $target" $cmd $base]
  51.     if {$r == -1} {
  52.         return
  53.     } else {
  54.         $target conf $option [string trim $r]
  55.     }
  56. }
  57.  
  58. proc vTcl:get_command {title initial base} {
  59.     global vTcl
  60.     if [winfo exists $base] {wm deiconify $base; return -1}
  61.     set vTcl(x,$base) -1
  62.     toplevel $base -class vTcl
  63.     wm transient $base .vTcl
  64.     wm geometry $base $vTcl(pr,geom_comm)
  65.     wm resizable $base 1 1
  66.     wm title $base $title
  67.     set vTcl(comm,$base,chg) 0
  68.     frame $base.f \
  69.         -borderwidth 2 -height 30 -relief groove -width 30 
  70.     pack $base.f \
  71.         -in $base -anchor center -expand 1 -fill both -ipadx 0 -ipady 0 \
  72.         -padx 3 -pady 3 -side top 
  73.     text $base.f.text \
  74.         -height 2 -width 2 -wrap none \
  75.         -yscrollcommand "$base.f.scrollbar16 set"
  76.     pack $base.f.text \
  77.         -in $base.f -anchor center -expand 1 -fill both -ipadx 0 \
  78.         -ipady 0 -padx 0 -pady 0 -side left 
  79.     scrollbar $base.f.scrollbar16 \
  80.         -borderwidth 1 -command "$base.f.text yview"
  81.     pack $base.f.scrollbar16 \
  82.         -in $base.f -anchor center -expand 0 -fill y -ipadx 0 -ipady 0 \
  83.         -padx 0 -pady 0 -side left 
  84.     frame $base.f21 \
  85.         -borderwidth 1 -height 30 -relief sunken -width 30 
  86.     pack $base.f21 \
  87.         -in $base -anchor center -expand 0 -fill x -ipadx 0 -ipady 0 \
  88.         -padx 3 -pady 3 -side top 
  89.     button $base.f21.button22 \
  90.         -command "vTcl:command:edit_save $base" \
  91.         -padx 9 \
  92.         -pady 3 -text OK -width 5 
  93.     pack $base.f21.button22 \
  94.         -in $base.f21 -anchor center -expand 1 -fill x -ipadx 0 -ipady 0 \
  95.         -padx 0 -pady 0 -side left 
  96.     button $base.f21.button23 \
  97.         -command "
  98.             vTcl:command:edit_cancel $base
  99.         " \
  100.          -padx 9 \
  101.         -pady 3 -text Cancel -width 5 
  102.     pack $base.f21.button23 \
  103.         -in $base.f21 -anchor center -expand 1 -fill x -ipadx 0 -ipady 0 \
  104.         -padx 0 -pady 0 -side left 
  105.     update idletasks
  106.     bind $base <KeyPress> "
  107.         set vTcl(comm,$base,chg) 1
  108.     "
  109.     bind $base <Key-Escape> "
  110.         vTcl:command:edit_save $base
  111.         break
  112.     "
  113.     $base.f.text delete 0.0 end
  114.     $base.f.text insert end $initial
  115.     focus $base.f.text
  116.     tkwait window $base
  117.     update idletasks
  118.     switch -- $vTcl(x,$base) {
  119.         "-1"      {return -1}
  120.         default "return $vTcl(x,$base)"
  121.     }
  122. }
  123.  
  124. proc vTcl:command:save_geom {base} {
  125.     global vTcl
  126.     set vTcl(pr,geom_comm) [lindex [split [wm geom $base] +-] 0]
  127. }
  128.  
  129. proc vTcl:command:edit_save {base} {
  130.     global vTcl
  131.     vTcl:command:save_geom $base
  132.     set vTcl(x,$base) [$base.f.text get 0.0 end]
  133.     destroy $base
  134. }
  135.  
  136. proc vTcl:command:edit_cancel {base} {
  137.     global vTcl
  138.     vTcl:command:save_geom $base
  139.     if {$vTcl(comm,$base,chg) == 0} {
  140.         grab release $base
  141.         destroy $base
  142.     } else {
  143.         vTcl:dialog "Buffer has changed. Do you\nwish to save the changes?" {Yes No Cancel}
  144.         switch $vTcl(x_mesg) {
  145.             No {
  146.                 grab release $base
  147.                 destroy $base
  148.             }
  149.             Yes {vTcl:command:edit_save $base}
  150.             Cancel {}
  151.         }
  152.     }
  153. }
  154.  
  155.